package com.dyx.api.files.controller;


import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.jboss.netty.util.internal.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.io.UnsupportedEncodingException;
import javax.servlet.ServletContext;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.math.BigDecimal;

/**
 * Created by Administrator on 2017/9/27 0027.
 */

@RestController
@RequestMapping("/appSide")
public class ControllerByXJ extends BaseController {

    @Autowired
    private Environment env;




    //---------------------------------------订单服务-----------------------------------------------
    @RequestMapping(value = "/getpaymentrecordForMob", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "/getpaymentrecordForMob", notes = "获取移动端支付记录")
    @ApiImplicitParam(name = "param", value = "JSON格式消息对象", required = true,
            dataType = "{\"orderNum\":\"1\"//订单号}")
    public String getpaymentrecordForMob(@RequestBody JSONObject param) {
        try {
            JSONObject resultData = selectOtherModule(env.getProperty("rest.OrdersConroller"),env.getProperty("rest.OrdersConroller.getpaymentrecordForMob"),param);
            return resultData.toString();        } catch (Exception e) {
            e.printStackTrace();
            return returnErrorMessage("服务器繁忙,请稍后重试!");
        }
    }

    @RequestMapping(value = "/getprocessRecord", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "/getprocessRecord", notes = "获取订单操作日志")
    @ApiImplicitParam(name = "param", value = "JSON格式消息对象", required = true,
            dataType = "{\"orderNum\":\"1\"//订单号}")
    public String getprocessRecord(@RequestBody JSONObject param) {
        try {
            JSONObject resultData = selectOtherModule(env.getProperty("rest.OrdersConroller"),env.getProperty("rest.OrdersConroller.getprocessRecord"),param);
            return resultData.toString();        } catch (Exception e) {
            e.printStackTrace();
            return returnErrorMessage("服务器繁忙,请稍后重试!");
        }
    }


    @RequestMapping(value = "/getOrderReportForMob", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "/getOrderReportForMob", notes = "获取订单报表(移动端)")
    @ApiImplicitParam(name = "param", value = "JSON格式消息对象", required = true,
            dataType = "{\"tenantId\":\"2\",//租户ID}")
    public String getOrderReportForMob(@RequestBody JSONObject param) {
        try {
            param.put("tenantId",getSessionUserLesseeId());
            JSONObject resultData = selectOtherModule(env.getProperty("rest.OrdersConroller"),env.getProperty("rest.OrdersConroller.getOrderReportForMob"),param);
            return resultData.toString();        } catch (Exception e) {
            e.printStackTrace();
            return returnErrorMessage("服务器繁忙,请稍后重试!");
        }
    }



    @RequestMapping(value = "/selectOrderDetails", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "/selectOrderDetails", notes = "订单详情")
    @ApiImplicitParam(name = "param", value = "JSON格式消息对象", required = true,
            dataType = "{\"orderId\":\"792f5a74908011e7aa36448a5b9a271b\"//订单ID}")
    public String selectOrderDetails(@RequestBody JSONObject param) {
        try {
            JSONObject resultData = selectOtherModule(env.getProperty("rest.OrdersConroller"),env.getProperty("rest.OrdersConroller.orderDetails"),param);
            return resultData.toString();        } catch (Exception e) {
            e.printStackTrace();
            return returnErrorMessage("服务器繁忙,请稍后重试!");
        }
    }

    //--------------------------------渠道管理--------------------

    @RequestMapping(value = "selectPurchasingList", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "/selectPurchasingList", notes = "获取采购渠道列表")
    @ApiImplicitParam(name = "param", value = "JSON格式消息对象", required = true, dataType = "{  \"tenantId\":\"1\",//当前租户ID  \"tenantType\":\"0\",//当前租户类型  0零售商 1批发商 \"state\":\"0\",//状态  0=已签约、1=签约申请中  \"key\":\"品\" //查询关键字}")
    public String selectPurchasingList(@RequestBody JSONObject param) {
        try {
            //param.put("tenantId",getSessionUserLesseeId());
            param.put("tenantId",getSessionUserLesseeId());
            param.put("tenantType",getSessionUser().getString("tenChannel"));
            param.put("city", getSessionUser().getString("cityName"));
            //行业ID
            param.put("baseinfoId", getSessionUser().getString("tenIndustry"));
            JSONObject resultData = selectOtherModule(env.getProperty("rest.ChannelConroller"),env.getProperty("rest.ChannelConroller.getPurchasingList"),param);
            return resultData.toString();        } catch (Exception e) {
            e.printStackTrace();
            return returnErrorMessage("服务器繁忙,请稍后重试!");
        }
    }


    @RequestMapping(value = "/applyContract", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "/applyContract", notes = "采购申请签约,取消申请")
    @ApiImplicitParam(name = "param", value = "JSON格式消息对象", required = true, dataType = "申请签约 :{  \"brandUrl\": \"wwww.1234.com\",  //品牌LOGOURL  \"brandName\": \"品牌名称\", \"brandId\": 1,  //品牌ID  \"operationFlag\": \"1\", //0申请直发1申请签约2取消申请 \"requisitionReason\":\"申请理由\", \"upstreamUserId\":\"123123\"上游渠道用户ID,  \"upstreamUserShowId\":123,//上游渠道用户展示ID \"upstreamChannelId\": 4,  //上游渠道ID  \"upstreamChannelName\": \"渠道名称\",  \"upstreamChannelType\": 1,//上游渠道认证类型(1=品牌厂商、0=批发商) \"//上游渠道手机号 \"authorizationType\":\"1\",//授权类型  \"city\":\"城市\",  \"province\":\"省\",  \"area\":\"区\",\"id\":1//采购渠道ID} 取消申请: { \"operationFlag\":\"2\",//0申请直发 1申请签约 2取消申请  \"id\":16}")
    public String applyContract(@RequestBody JSONObject param) {
        try {
            //param.put("tenantId",getSessionUserLesseeId());
            //当前用户ID
            param.put("requisitionId",getSessionUser().getString("userId"));
            //当前租户ID
            param.put("requisitionTenantId",getSessionUserLesseeId());
            //当前企业名称
            param.put("requisitionTenantName",getSessionUser().getString("enterpriseName"));
            //当前用户展示ID
            param.put("requisitionShowId",getSessionUser().getString("userShowId"));
            //当前租户渠道类型
            param.put("requisitionChannelType",getSessionUser().getString("tenChannel"));
            //当前用户名称
            param.put("requisitionUserName",getSessionUser().getString("userName"));
            //当前行业展示ID
            param.put("industrieId", getSessionUser().getString("industrieShowId"));
            //当前一级分类
            param.put("firstIndustriesName",getSessionUser().getString("fristLevelModule"));
            //当前二级分类
            param.put("secondIndustriesName",getSessionUser().getString("twoLevelModule"));

            JSONObject resultData = selectOtherModule(env.getProperty("rest.ChannelConroller"),env.getProperty("rest.ChannelConroller.applyContract"),param);
            return resultData.toString();        } catch (Exception e) {
            e.printStackTrace();
            return returnErrorMessage("服务器繁忙,请稍后重试!");
        }
    }

    @RequestMapping(value = "shieldClient", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "/shieldClient", notes = "屏蔽采购客户")
    @ApiImplicitParam(name = "param", value = "json格式对象", required = true, dataType="\n" +
            "{\"id\":\"16\",//采购客户ID\"flag\":\"0\",//操作flag 0取消 1 屏蔽\"handlers\":\"3323\" //操作人ID}")
    public String shieldClient(@RequestBody JSONObject param) {
        try {
            param.put("handlers",getSessionUserId());//操作人ID
            JSONObject resultData = selectOtherModule(env.getProperty("rest.ChannelConroller"),env.getProperty("rest.ChannelConroller.shieldClient"),param);
            return resultData.toString();        } catch (Exception e) {
            e.printStackTrace();
            return returnErrorMessage("服务器繁忙,请稍后重试!");
        }
    }


    @RequestMapping(value = "/toApplyContract", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "/toApplyContract", notes = "转至申请签约页面")
    @ApiImplicitParam(name = "param", value = "json对象", required = true, dataType = "{\"upstreamChannelId\": 4, //上游渠道ID\"  \"brandUrl\": \"wwww.1234.com\",//品牌  \"brandName\": \"品牌名称\",  \"brandId\": 1,//品牌ID   \"requisitionTenantName\": \"企业名称\",//申请签约单位  \"requisitionChannelType\": \"1\", //申请渠道类型(0=零售商 1=批发商)  \"sentAddress\":\"发货地址\", “isAuthorize\":\"fasle\",//是否授权  \" upstreamChannelName\": \"渠道名称\",//单位类型  \"upstreamChannelType\": 1,  //单位类型(1=品牌厂商、0=批发商)}")
    public String toApplyContract(@RequestBody JSONObject param) {
        try {
            param.put("tenantId",getSessionUserLesseeId());
            //租户电话
            param.put("userTel",getSessionUser().getString("userTel"));
            //企业名称
            param.put("requisitionTenantName",getSessionUser().getString("enterpriseName"));
            //申请渠道类型(0=零售商 1=批发商
            param.put("requisitionChannelType",getSessionUser().getString("tenChannel"));
            JSONObject resultData = selectOtherModule(env.getProperty("rest.ChannelConroller"),env.getProperty("rest.ChannelConroller.toApplyContract"),param);
            return resultData.toString();        } catch (Exception e) {
            e.printStackTrace();
            return returnErrorMessage("服务器繁忙,请稍后重试!");
        }
    }

    @RequestMapping(value = "/directSendContract", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "/directSendContract", notes = "采购申请直发")
    @ApiImplicitParam(name = "purchasingRequisitionVO", value = "采购渠道对象", required = true, dataType = " { \"operationFlag\":\"0\",//0申请直发 1申请签约 2取消申请 \"id\":1//采购渠道ID }")
    public String directSendContract(@RequestBody JSONObject param) {
        try {
            JSONObject resultData = selectOtherModule(env.getProperty("rest.ChannelConroller"),env.getProperty("rest.ChannelConroller.directSendContract"),param);
            return resultData.toString();        } catch (Exception e) {
            e.printStackTrace();
            return returnErrorMessage("服务器繁忙,请稍后重试!");
        }
    }

    @RequestMapping(value = "/relieveApplyCg", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "/relieveApplyCg", notes = "采购客户:解约")
    @ApiImplicitParam(name = "param", value = "json格式对象", required = true, dataType="{\"id\":\"962538e18a3911e7b385448a5b9a271b\"/销售客户ID}")
    public String relieveApplyCg(@RequestBody JSONObject param) {
        try {
            JSONObject resultData = selectOtherModule(env.getProperty("rest.ChannelConroller"),env.getProperty("rest.ChannelConroller.relieveApplyCg"),param);
            return resultData.toString();        } catch (Exception e) {
            e.printStackTrace();
            return returnErrorMessage("服务器繁忙,请稍后重试!");
        }
    }

    /**
     * 首页获取可采购品牌数,供货商 可采购商品数(采购)
     */
    @RequestMapping(value = "/selectPurchasingImfo", method = RequestMethod.POST)
    @ApiOperation(value = "/selectPurchasingImfo", notes = "获取可采购品牌数,供货商 可采购商品数")
    @ApiImplicitParam(name = "param", value = "json格式对象", required = true, dataType = "\n" +
            "{}")
    public String selectPurchasingImfo(@RequestBody JSONObject param) {
        try{
            //param.put("tenantId",getSessionUserLesseeId());
            param.put("tenantId",getSessionUserLesseeId());
            JSONObject resultData = selectOtherModule(env.getProperty("rest.ChannelConroller"),env.getProperty("rest.ChannelConroller.getPurchasingImfo"),param);
            return resultData.toString();
        }catch (Exception e){
            e.printStackTrace();
            return returnErrorMessage("服务器繁忙,请稍后重试!");
        }
    }


    /**
     * 移动端 获取支付订单详情
     */
    @RequestMapping(value = "/paymentShopOrderMob", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "/paymentShopOrderMob", notes = "移动端 获取支付订单详情")
    @ApiImplicitParam(name = "param", value = "JSON格式消息对象", required = true,
            dataType = "{\"orderId\":\"2\"//订单ID}")
    public String paymentShopOrderMob(@RequestBody JSONObject param) {
        try{
            JSONObject resultData = selectOtherModule(env.getProperty("rest.OrdersConroller"),env.getProperty("rest.OrdersConroller.paymentShopOrderMob"),param);
            return resultData.toString();
        }catch (Exception e){
            e.printStackTrace();
            return returnErrorMessage("服务器繁忙,请稍后重试!");
        }
    }

    @RequestMapping(value = "/toPayPage", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "/toPayPage", notes = "转至分期支付页面")
    @ApiImplicitParam(name = "param", value = "JSON格式消息对象", required = true,
            dataType = "{\"orderId\":\"792f5a74908011e7aa36448a5b9a271b\"//订单ID}")
    public String toPayPage(@RequestBody JSONObject param) {
        try {
            param.put("uType",1);
            param.put("tenantId", getSessionUserLesseeId());
            JSONObject resultData = selectOtherModule(env.getProperty("rest.OrdersConroller"), env.getProperty("rest.OrdersConroller.toPayPage"), param);
            return resultData.toString();
        } catch (Exception e) {
            e.printStackTrace();
            return returnErrorMessage("服务器繁忙,请稍后重试!");
        }
    }

    //------------------------------商城--------------------------------
    /**
     * 获取商城商品
     */
    @RequestMapping(value = "/selectMallGoodsList", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "/selectMallGoodsList", notes = "获取商城商品")
    @ApiImplicitParam(name = "param", value = "JSON格式消息对象", required = true,
            dataType = "{\"tenantId\":1//当前租户ID,\"brandIds\": 1//品牌ID数组, \" channelType\":\"1\" //渠道类型 0  批发商 1 厂商," +
                    "sendAddressDetail:1231//收货地址 \"signingMethod\":0//签约类型0 综合 1 已签约 2 未签约,upJiaFlag = \"0\" //上架时间 0 低 1 高 String priceFlag = \"0\"; //价格 0 低 1 高 \"purchaseFlag\":0//采购flag 0 未采购 1 已采购}")
    public String selectMallGoodsList(@RequestBody JSONObject param) throws Exception {
        try {
            JSONObject resultData =  new JSONObject();
            param.put("tenantId",getSessionUserLesseeId());
            param.put("chanelType", getSessionUser().getString("tenChannel"));
            param.put("flag","0");
            //0 综合 1 已签约 2 未签约 3 已采购
            //param.put("signingMethod","0");
            if(param.containsKey("signingMethod")){
                if("0".equals(param.getString("signingMethod"))){
                    //无采购标识
                    if(!param.containsKey("purchaseFlag") || StringUtils.isBlank(param.getString("purchaseFlag"))){
                        resultData = selectOtherModule(env.getProperty("rest.GoodsConroller"),env.getProperty("rest.GoodsConroller.getMallGoodsList"),param);
                    }
                    else{
                        resultData = selectOtherModule(env.getProperty("rest.GoodsConroller"),env.getProperty("rest.GoodsConroller.getPurchaseGoodsList"),param);
                    }
                }
                else if("1".equals(param.getString("signingMethod"))){
                    //无采购标识
                    if(!param.containsKey("purchaseFlag") || StringUtils.isBlank(param.getString("purchaseFlag"))){
                        resultData = selectOtherModule(env.getProperty("rest.GoodsConroller"),env.getProperty("rest.GoodsConroller.getSignedGoodsList"),param);
                    }
                    else{
                        resultData = selectOtherModule(env.getProperty("rest.GoodsConroller"),env.getProperty("rest.GoodsConroller.getPurchaseGoodsList"),param);
                    }
                }
                else if("2".equals(param.getString("signingMethod"))){
                    resultData = selectOtherModule(env.getProperty("rest.GoodsConroller"),env.getProperty("rest.GoodsConroller.getUnSignedGoodsList"),param);
                }

            }
            return resultData.toString();        } catch (Exception e) {
            e.printStackTrace();
            return returnErrorMessage("服务器繁忙,请稍后重试!");
        }
    }


    /**
     *商品详情
     */
    @RequestMapping(value = "/selectGoodsBuyDetails", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "/selectGoodsBuyDetails", notes = "商品详情")
    @ApiImplicitParam(name = "param", value = "JSON格式消息对象", required = true,
            dataType = "{\"goodsShowId\":1}")
    public String selectGoodsBuyDetails(@RequestBody JSONObject param) throws Exception {
        try {
            JSONObject resultData = selectOtherModule(env.getProperty("rest.GoodsConroller"),env.getProperty("rest.GoodsConroller.getGoodsBuyDetails"),param);
            return resultData.toString();        } catch (Exception e) {
            e.printStackTrace();
            return returnErrorMessage("服务器繁忙,请稍后重试!");
        }
    }

    /**
     *查询规格价格
     */
    @RequestMapping(value = "/getsPecificationsPrice", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "/getsPecificationsPrice", notes = "查询规格价格")
    @ApiImplicitParam(name = "param", value = "JSON格式消息对象", required = true,
            dataType = "{\"specificationsId\":[\"1\",\"2\"],//规格类型数组\"detachmentId\":\"333\",//租户在该商品中分队\"groupId\":\"3\"//租户在该商品中分组}")
    public String getsPecificationsPrice(@RequestBody JSONObject param) throws Exception {
        try {
            param.put("tenantId", getSessionUserLesseeId());
            JSONObject resultData = selectOtherModule(env.getProperty("rest.GoodsConroller"),env.getProperty("rest.GoodsConroller.getsPecificationsPrice"),param);
            return resultData.toString();        } catch (Exception e) {
            e.printStackTrace();
            return returnErrorMessage("服务器繁忙,请稍后重试!");
        }
    }

    /**
     * 加入商品致购物车
     */
    @RequestMapping(value = "/addShopCar", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "/addShopCar", notes = "加入商品致购物车")
    @ApiImplicitParam(name = "shopCarVO", value = "JSON格式消息对象", required = true,
            dataType = "{\"deposit\": 0,//定金  \"goodsId\": \"ertetertert\",//商品ID \"number\": 0,//订货数量 \"price\": 0,//单个价格  \"tenantId\": \"wrwer\",//所属租ID}")
    public String addShopCar(@RequestBody JSONObject param) {
        try {
            param.put("tenantId", getSessionUserLesseeId());
            JSONObject resultData = selectOtherModule(env.getProperty("rest.OrdersConroller"),env.getProperty("rest.OrdersConroller.addShopCar"),param);
            return resultData.toString();        } catch (Exception e) {
            e.printStackTrace();
            return returnErrorMessage("服务器繁忙,请稍后重试!");
        }
    }


    /**
     * 删除购物车
     */
    @RequestMapping(value = "/deleteShopCar", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "/deleteShopCar", notes = "删除购物车列表")
    @ApiImplicitParam(name = "param", value = "JSON格式消息对象", required = true,
            dataType = "{\"ids\":[\"1\",\"2\",\"4\"]//商品Id数组}")
    public String deleteShopCar(@RequestBody JSONObject param) {
        try {
            param.put("tenantId", getSessionUserLesseeId());
            JSONObject resultData = selectOtherModule(env.getProperty("rest.OrdersConroller"), env.getProperty("rest.OrdersConroller.deleteShopCar"), param);
            return resultData.toString();
        } catch (Exception e) {
            e.printStackTrace();
            return returnErrorMessage("服务器繁忙,请稍后重试!");
        }
    }


    /**
     * 获取购物车
     *
     */
    @RequestMapping(value = "/selectShopCarList", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "/selectShopCarList", notes = "获取购物车列表")
    @ApiImplicitParam(name = "param", value = "JSON格式消息对象", required = true,
            dataType = "{}")
    public String selectShopCarList(@RequestBody JSONObject param) {
        try {
            param.put("tenantId",getSessionUserLesseeId());
            JSONObject resultData = selectOtherModule(env.getProperty("rest.OrdersConroller"),env.getProperty("rest.OrdersConroller.getShopCarList"),param);
            return resultData.toString();        } catch (Exception e) {
            e.printStackTrace();
            return returnErrorMessage("服务器繁忙,请稍后重试!");
        }
    }

    @RequestMapping(value="/selectBuyOrder", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "/selectBuyOrder" ,notes ="订单中心-采购订单-查询列表")
    @ApiImplicitParam(name = "param", required = true, dataType = "{\"key\":\"搜索关键字\",\"brandId\":\"品牌id\"," +
            "\"status\":\"订单状态,1=已取消，2=待支付定金、3=待支付余款、4=待发货、5=待收货、6=已收货、7=已完成\"," +
            "\"saleTenantId\":\"卖方租户ID\",\"startTime\":\"日期\",\"endTime\":\"日期\"}")
    public String selectBuyOrder(@RequestBody JSONObject param){
        try{
            param.put("flag","0");
            param.put("tenantId",getSessionUserLesseeId());
            JSONObject resultData = selectOtherModule(env.getProperty("rest.OrdersConroller"),env.getProperty("rest.OrdersConroller.getShopOrder"),param);
            return resultData.toJSONString();
        }catch (Exception e){
            return returnErrorMessage("服务器繁忙,请稍后重试!");
        }
    }

    @RequestMapping(value = "/selectPurchaseReport", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "/selectPurchaseReport", notes = "商品报表(采购)")
    @ApiImplicitParam(name = "param", value = "JSON格式消息对象", required = true,
            dataType = "{\"timeType\":\"custom\",//时间类型today,yesterday,week,mouth,custom 自定义 \"startTime\":\"2017-01-01\",//开始时间\"endTime\":\"2017-09-08\",//结束时间\"brandName\":\"品牌55\",//品牌名称\"enterpriseName\":\"企业名称222\"//企业名称}")
    public String selectPurchaseReport(@RequestBody JSONObject param) {
        try {
            param.put("tenantId",getSessionUserLesseeId());
            JSONObject resultData = selectOtherModule(env.getProperty("rest.ReportConroller"),env.getProperty("rest.ReportConroller.purchaseReport"),param);
            return resultData.toString();        } catch (Exception e) {
            e.printStackTrace();
            return returnErrorMessage("服务器繁忙,请稍后重试!");
        }
    }

    /**
     * 获取已采购的品牌(采购品牌调用)
     */
    @RequestMapping(value = "selectPurchaseBrand", method = RequestMethod.POST)
    @ApiOperation(value = "/selectPurchaseBrand", notes = "获取已采购的品牌(采购品牌调用)")
    @ApiImplicitParam(name = "param", value = "JSON格式消息对象", required = true,
            dataType = "{\"userId\":1//用户ID}")
    public String selectPurchaseBrand(@RequestBody JSONObject param) {
        try {
            param.put("tenantId", getSessionUserLesseeId());
            JSONObject resultData = selectOtherModule(env.getProperty("rest.ChannelConroller"), env.getProperty("rest.ChannelConroller.getPurchaseBrand"), param);
            return resultData.toString();
        } catch (Exception e) {
            e.printStackTrace();
            return returnErrorMessage("服务器繁忙,请稍后重试!");
        }
    }

    /**
     * 下单
     */
    @RequestMapping(value = "/generateOrder", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "/generateOrder", notes = "生成订单")
    @ApiImplicitParam(name = "param", value = "JSON格式消息对象", required = true,
            dataType = "{  \"remarks\": \"备注\",    \"receiptId\": \"收货地址ID\",   \"receiptName\": \"收货地址\", \"receiptUser\": \"收货人\", \"receiptPhone\": \"收货电话\", \"totalPrice\": 123,//总价  \"totalDeposit\": 343,//总定金 \"goodNum\": \"1234\",//总产品数  \"firstIndustriesName\": \"23424\",//一级分类   \"secondIndustriesName\": \"2434\",//二级分类   \"industrieId\": \"erter\",//行业ID  \"tableData\": [//子订单数组   {  \"brandIconUrl\": \"data/module/common/yadi.png\",//品牌URL  \"supplier\": \"企业名称222\",  \"sendAddress\": {//发货地址  \"addressId\": \"24234\",//发货地址ID  \"addressName\": \"发货地址5\",//发货地址名称  \"location\": {//经纬度 \"lat\": \"31.546428\", //经度 \"lng\": \"120.304342\"//纬度  }   },  \"detail\": [ //购物车商品数组   { \"isCheck\": false,  \"id\": 1,//购物车商品ID \"brandIconUrl\": \"data/module/common/yadi.png\",//品牌URL   \"sendAddressId\": \"4444\",//发货地址ID   \"brandName\": \"品牌55\", \"goodsCode\": \"ABCDEFG\",//商品编号  \"imgUrl\": \"商品图片地址\", \"barCode\": \"商品条码\",  \"salesUserShowId\": \"34234\",//卖家用户展示ID  \"salesUserPhone\": \"1233242342\",//卖家电话  \"sellTenantId\": \"1233535342\",//卖家租户ID  \"goodsId\": \"eee494b142684f93a30af9af36bb16af\",//商品ID   \"goodsName\": \"雅迪电动车-亮黑版\",//商品名称 \"goodsInfo\": \"商品简介商品简介商品简介商品简介\",  \"unit\": \"台\",  \"model\": \"中国红/黑-含包装-不含充电器\",//商品规格  \"stock\": 1,//商品库存  \"price\": 1990,//商品价格 \"number\": 1,//购买商品数量 \"total\": 30,//总价 \"deposit\": 2000//总金额 }] }]}")
    public String generateOrder(@RequestBody JSONObject param) {
        try {
            //租户ID
            param.put("tenantId", getSessionUserLesseeId());
            //提交人展示ID
            param.put("submitterShowId", getSessionUser().getString("userShowId"));
            //提交人电话
            param.put("submitterPhone", getSessionUser().getString("userTel"));
            //一级分类
            param.put("firstIndustriesName", getSessionUser().getString("fristLevelModule"));
            //二级分类
            param.put("secondIndustriesName", getSessionUser().getString("twoLevelModule"));
            //行业展示ID
            param.put("industrieId", getSessionUser().getString("industrieShowId"));
            //当前企业名称
            param.put("requisitionTenantName", getSessionUser().getString("enterpriseName"));
            JSONObject resultData = selectOtherModule(env.getProperty("rest.OrdersConroller"), env.getProperty("rest.OrdersConroller.generateOrder"), param);
            return resultData.toString();
        } catch (Exception e) {
            e.printStackTrace();
            return returnErrorMessage("服务器繁忙,请稍后重试!");
        }
    }

    /**
     * 首页获取 消息信息
     */
    @RequestMapping(value = "/getMessageByFilter", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "/getMessageByFilter", notes = "根据条件查询消息")
    @ApiImplicitParam(name = "param", value = "JSON格式消息对象", required = true, dataType = "{" +
            "\"messageType\":1,\"messageReceiveUser\":\"消息接收对象,long类型\"}")
    public String getMessageByFilter(@RequestBody JSONObject param) {
        try {
            param.put("messageReceiveUser", getSessionUserLesseeId());
            JSONObject resultData = selectOtherModule(env.getProperty("rest.Controller"), env.getProperty("rest.Controller.getMessageByFilter"), param);
            return resultData.toString();
        } catch (Exception e) {
            e.printStackTrace();
            return returnErrorMessage("服务器繁忙,请稍后重试!");
        }
    }

    @RequestMapping(value="/updateCancelBuyOrder", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "/updateCancelBuyOrder" ,notes ="订单中心-取消订单")
    @ApiImplicitParam(name = "param", required = true, dataType = "{\"orderId\":\"订单id\"}")
    public String updateCancelBuyOrder(@RequestBody JSONObject param){
        try{
            JSONObject resultData = selectOtherModule(env.getProperty("rest.OrdersConroller"),env.getProperty("rest.OrdersConroller.cancelOrder"),param);
            return resultData.toJSONString();
        }catch (Exception e){
            return returnErrorMessage("服务器繁忙,请稍后重试!");
        }
    }

    @RequestMapping(value="/selectBrandQuota", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "/selectBrandQuota" ,notes ="查询企业授信")
    @ApiImplicitParam(name = "param", required = true, dataType = "{}")
    public String selectBrandQuota(@RequestBody JSONObject param){
        try{
            param.put("lesseeId",getSessionUserLesseeId());
            JSONObject resultData = selectOtherModule(env.getProperty("rest.ChannelConroller"),env.getProperty("rest.ChannelConroller.getBrandQuota"),param);
            return resultData.toJSONString();
        }catch (Exception e){
            return returnErrorMessage("服务器繁忙,请稍后重试!");
        }
    }

    @RequestMapping(value="/applyQuota", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "/applyQuota" ,notes ="申请授信")
    @ApiImplicitParam(name = "param", required = true, dataType = "{\"id\":\"采购品牌id\"}")
    public String applyQuota(@RequestBody JSONObject param){
        try{
            JSONObject user = getSessionUser();
            param.put("quota",new BigDecimal(100000));
            param.put("lesseeId",getSessionUserLesseeId());
            JSONObject resultData = selectOtherModule(env.getProperty("rest.ChannelConroller"),env.getProperty("rest.ChannelConroller.applyQuota"),param);
            return resultData.toJSONString();
        }catch (Exception e){
            return returnErrorMessage("服务器繁忙,请稍后重试!");
        }
    }
}
